#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QChartView>
#include <QChart>
#include <QLineSeries>
#include <QTimer>
#include <QDebug>
#include <QValueAxis>

#include <QModbusClient>
#include <QModbusRtuSerialMaster>

#include <SetSerialDialog.h>
#include <SetModbusDialog.h>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
using namespace QT_CHARTS_NAMESPACE;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_actionSetModbus_triggered();
    void on_actionSetSerial_triggered();
    void on_pushButton_start_released();

private:
    /**
     * @brief _ChartUiInit
     */
    void _ChartUiInit();
    Ui::MainWindow *ui;

    QChartView *u_chartView;
    std::shared_ptr<QChart> u_chart;
    QLineSeries *u_lineSeries;
    QValueAxis * u_axisX;
    QValueAxis * u_axisY;
    qreal u_axisX_x=0;

    /**
     * @brief _ModbusConnect
     */
    void _ModbusConnect();
    /**
     * @brief 发送请求
     */
    void _ModbusRequests(QModbusDataUnit::RegisterType regType, int newStartAddress, quint16 newValueCount,int serverAddress);
    /**
     * @brief modbus接收槽
     */
    void _onModbusReadReady();
    QModbusClient *m_modbusDevice;
    QModbusDataUnit m_modbusDataUnit;
    std::function<void()> m_modbusRequests;


    SetSerialDialog m_setSerialDialog;
    SetModbusDialog m_setModbusDialog;
};
#endif // MAINWINDOW_H
